package com.lijie.ljblog.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lijie.ljblog.mapper.TestMapper;
import com.lijie.ljblog.model.Test;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author 李杰
 * @create 2024-05-31-14:55
 */
@Service
public class TestServiceImpl extends ServiceImpl<TestMapper, Test> {


    @Resource
    TestServiceImpl testService;

    public int updateA(){
        this.baseMapper.update(null,new LambdaUpdateWrapper<Test>().set(Test::getA,"A"));
        return 1;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public int updateB(){
        this.baseMapper.update(null,new LambdaUpdateWrapper<Test>().set(Test::getB,"B"));
            return 1;
    }

    @Transactional()
    public void update(String x){
        updateA();
        try{
            //直接使用B 应该不会生效
            testService.updateB();
        }catch (Exception e){
            System.out.println(e);
        }
        int xx =1/0;
        System.out.println(x);

    }

    @Transactional
    public void updateABcommon(){
        this.updateA();

    }



}
